<?php

namespace App\Models;

use App\Constant\UserFollowTypeCode;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * Class UserFollows
 * Description:用户埋点信息表
 * Author: cg
 * DateTime: 2019/3/6 14:05
 */
class UserFollow extends Model
{
    protected $guarded = ['id'];

    const USER_FOLLOW_FLAG = [
        'day' => '按天统计',
        'month' => '按月统计',
        'hour' => '按时统计'
    ];

    /**
     * 代表埋点追踪请求成功的数据
     */
    const CODE_SUCCESS = 200;


    /**
     * 设备
     */
    const DEVICE_IOS = 1;
    const DEVICE_ANDROID = 2;
    const DEVICE_H5 = 3;
    const DEVICE_DESC = [
        self::DEVICE_IOS => 'ios',
        self::DEVICE_ANDROID => 'android',
        self::DEVICE_H5 => 'h5',
    ];

    public function filterType($type, $data)
    {
        //暂不实现
        return $data;
    }














//    /**
//     * Description: 获取指定时间段内按照天,月或小时的分组数据
//     * Author: cg
//     * DateTime: 2019-03-09 12:42
//     */
//    public function queryDatas($channel_lock, $flag, $start, $end, $channel = false, $type = false){
//        $resultBuild = (new UserFollow())->setConnection('backend')->select(
//            'type',
//            DB::raw("count( DISTINCT user_id ) AS num"),
//            DB::raw("(CASE
//			WHEN '{$flag}' = 'day' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d' )
//			WHEN '{$flag}' = 'hour' THEN
//			DATE_FORMAT( created_at , '%Y-%m-%d %H' )
//			WHEN '{$flag}' = 'month' THEN
//			DATE_FORMAT( created_at, '%Y-%m' )
//	        ELSE created_at
//	        END
//	        )as flag"),
//            'channel'
//        )->whereRaw('code = ?', [200])
//            ->whereRaw('created_at >= ? AND created_at <= ?', [$start, $end]);
//        if($channel){
//            $resultBuild->whereIn('channel', explode(',', $channel));
//        }
//        if($flag && $channel_lock == 1){
//            $resultBuild->groupBy('type','flag','channel');
//        }
//        elseif($flag && $channel_lock == 2){
//            $resultBuild = $resultBuild->groupBy('type','flag');
//        }
//        elseif(!$flag && $channel_lock == 1){
//            $resultBuild = $resultBuild->groupBy('type','channel');
//        }
//        else{
//            $resultBuild = $resultBuild->groupBy('type');
//        }
//        if($type){
//            $resultBuild->havingRaw('type = ?', [$type]);
//        }
//        $result = $resultBuild->get()->toArray();
//
//        // PV
//        $sourceCount = new SourceCount();
//        $sourceCount->setConnection('backend');
//        $pv = $sourceCount->select(
//            DB::raw("(CASE
//			WHEN '{$flag}' = 'day' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d' )
//			WHEN '{$flag}' = 'hour' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d %H' )
//			WHEN '{$flag}' = 'month' THEN
//			DATE_FORMAT( created_at, '%Y-%m' )
//	        ELSE created_at
//	        END
//	        )as flag"),
//            DB::raw("count( ip ) AS pv"),
//            'source_id'
//        )->whereRaw('created_at >= ? AND created_at <= ?', [$start, $end]);
//        if($flag && $channel_lock == 1){
//            $pv = $pv->groupBy('flag', 'source_id')->get()->toArray();
//        }
//        elseif($flag && $channel_lock == 2){
//            $pv = $pv->groupBy('flag')->get()->toArray();
//        }
//        elseif(!$flag && $channel_lock == 1){
//            $pv = $pv->groupBy('source_id')->get()->toArray();
//        }
//        else{
//            $pv = $pv->get()->toArray();
//        }
//
//        // UV
//        $uv = $sourceCount->select(
//            DB::raw("(CASE
//			WHEN '{$flag}' = 'day' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d' )
//			WHEN '{$flag}' = 'hour' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d %H' )
//			WHEN '{$flag}' = 'month' THEN
//			DATE_FORMAT( created_at, '%Y-%m' )
//	        ELSE created_at
//	        END
//	        )as flag"),
//            DB::raw("count( DISTINCT ip ) AS uv"),
//            'source_id'
//        )->whereRaw('created_at >= ? AND created_at <= ?', [$start, $end]);
//        if($flag && $channel_lock == 1){
//            $uv = $uv->groupBy('flag', 'source_id')->get()->toArray();
//        }
//        elseif($flag && $channel_lock !== 1){
//            $uv = $uv->groupBy('flag')->get()->toArray();
//        }
//        elseif(!$flag && $channel_lock == 1){
//            $uv = $uv->groupBy('source_id')->get()->toArray();
//        }
//        else{
//            $uv = $uv->get()->toArray();
//        }
//
//        // 注册数
//        $user = new User();
//        $regNum = $user->select(
//            DB::raw("(CASE
//			WHEN '{$flag}' = 'day' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d' )
//			WHEN '{$flag}' = 'hour' THEN
//			DATE_FORMAT( created_at, '%Y-%m-%d %H' )
//			WHEN '{$flag}' = 'month' THEN
//			DATE_FORMAT( created_at, '%Y-%m' )
//	        ELSE created_at
//	        END
//	        )as flag"),
//            DB::raw("count(phone_num) as reg_num"),
//            'source'
//        )
//            ->whereRaw('created_at >= ? AND created_at <= ?', [$start, $end]);
//        if($flag && $channel_lock == 1){
//            $regNum = $regNum->groupBy('flag', 'source')->get()->toArray();
//        }
//        elseif($flag && $channel_lock == 2){
//            $regNum = $regNum->groupBy('flag')->get()->toArray();
//        }
//        elseif(!$flag && $channel_lock == 1){
//            $regNum = $regNum->groupBy('source')->get()->toArray();
//        }
//        else{
//            $regNum = $regNum->get()->toArray();
//        }
//
//        $ret = $this->formatNumData($result, $pv, $uv, $regNum, $flag, $channel_lock);
//        return $ret;
//    }


    /**
     * Description: 格式化所有节点数据
     * Author: cg
     * DateTime: 2019-03-09 13:20
     * @return array
     */
    public function formatNumData($arr, $pv, $uv, $regNum, $flag, $channel_lock)
    {
        $returnArr = [];
        $channel_arr = [];
        $flag_arr = [];
        foreach ($arr as $key => $item) {
            if (!empty($channel_arr) && !empty($flag_arr) && in_array($item['channel'], $channel_arr) && in_array($item['flag'], $flag_arr)) {
                continue;
            }
            $_arr = [];
            $_arr['type'] = $item['type'];
            $_arr['channel'] = $item['channel'];
            $_arr['channel_name'] = $this->getChannelName($item['channel']);
            $_arr['time'] = $item['flag'];
            $_arr['start_statistics_time'] = $this->getStatisticsTime($item['flag'], 'start', $flag); // 2018-5-9 10
            $_arr['end_statistics_time'] = $this->getStatisticsTime($item['flag'], 'end', $flag);
            $_arr['pv'] = 0;
            $_arr['uv'] = 0;
            $_arr['register_num'] = 0;
            $_arr['login_num'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_USER_LOGIN);
            $_arr['want_loan'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_BORROW_MONEY);
            $_arr['card_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_VERIFIED);
            $_arr['face_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_USER_FACE);
            $_arr['contact_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_CONTACT);
            $_arr['debit_card_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_BANK_DEBIT);
            $_arr['credit_card_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_BANK_CREDIT);
            $_arr['phone_auth'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_CERT_PHONE);
            $_arr['zhima_auth'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_CERT_ZHIMA);
            $_arr['auth_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_CERT_APPLY);
            $_arr['confirm_submit'] = $this->searchTypeByField($arr, $item['channel'], UserFollowTypeCode::TYPE_CONFIRM_APPLY);
            array_push($returnArr, $_arr);
            array_push($channel_arr, $item['channel']);
            array_push($flag_arr, $item['flag']);
        }

        $date_time1 = [];
        $date_time2 = [];
        $date_time3 = [];

        foreach ($returnArr as $k => &$v1) {
            if ($channel_lock == 2 && !$flag) {
                if ($k == 0) {
                    $v1['pv'] = array_sum(array_column($pv, 'pv'));
                }
                break;
            }
            foreach ($pv as $key => $_pv) {
                if ($channel_lock == 2 && $flag) {
                    if (!empty($date_time1) && in_array($v1['time'], $date_time1)) {
                        continue;
                    }
                    if ($_pv['flag'] == $v1['time']) {
                        array_push($date_time1, $v1['time']);
                        $v1['pv'] = $_pv['pv'];
                        break;
                    }
                }
                if ($v1['channel'] != $_pv['source_id']) continue;
                $v1['pv'] = $_pv['pv'];
                break;
            }

        }
        unset($v1);
        foreach ($returnArr as $k => &$v2) {
            if ($channel_lock == 2 && !$flag) {
                if ($k == 0) {
                    $v2['uv'] = array_sum(array_column($uv, 'uv'));
                }
                break;
            }
            foreach ($uv as $_uv) {
                if ($channel_lock == 2 && $flag) {
                    if (!empty($date_time2) && in_array($v2['time'], $date_time2)) {
                        continue;
                    }
                    if ($_uv['flag'] == $v2['time']) {
                        array_push($date_time2, $v2['time']);
                        $v2['uv'] = $_uv['uv'];
                        break;
                    }
                }
                if ($v2['channel'] == $_uv['source_id']) {
                    $v2['uv'] = $_uv['uv'];
                    break;
                }
            }
        }
        unset($v2);
        foreach ($returnArr as $k => &$v3) {
            if ($channel_lock == 2 && !$flag) {
                if ($k == 0) {
                    $v3['register_num'] = array_sum(array_column($regNum, 'reg_num'));
                }
                break;
            }
            foreach ($regNum as $_regNum) {
                $tmp = $_regNum['source'] ? $_regNum['source'] : 0;
                if ($channel_lock == 2 && $flag) {
                    if (!empty($date_time3) && in_array($v3['time'], $date_time3)) {
                        continue;
                    }
                    if ($_regNum['flag'] == $v3['time']) {
                        array_push($date_time3, $v3['time']);
                        $v3['register_num'] = $_regNum['reg_num'];
                        break;
                    }
                }
                if ($v3['channel'] == $tmp) {
                    $v3['register_num'] = $_regNum['reg_num'];
                    break;
                }
            }
        }
        unset($v3);
        return $returnArr;
    }

    /**
     * Description: 根据渠道和节点类型匹配用户数量
     * Author: cg
     * DateTime: 2019-03-09 13:20
     * @return int
     */
    private function searchTypeByField($arr, $channel, $type)
    {
        foreach ($arr as $v) {
            if (!empty($v)) {
                if ($v['type'] == $type && $v['channel'] == $channel) {
                    return $v['num'];
                }
            }
        }
        return 0;
    }

    /**
     * Description: 格式化前端显示时间段
     * Author: cg
     * DateTime: 2019-03-09 13:20
     * @return array
     */
    private function getStatisticsTime($time, $s, $flag)
    {
        if ($s == 'start') {
            if ($flag == 'hour') {
                return date("Y-m-d", strtotime($time . ':00:00'));
            } elseif ($flag == 'day' || empty($flag)) {
                return date("Y-m-d", strtotime($time));
            }
        } else {
            if ($flag == 'day' || empty($flag)) {
                return Carbon::parse($time)->addDay(1)->toDateString();
            } elseif ($flag == 'hour') {
                return date('H', strtotime("+1 hour", strtotime($time . ':00:00')));
//                return Carbon::parse($time.':00:00')->addHour(1)->toDateTimeString();
            } else {
//                return Carbon::parse($time)->addMonth(1)->toDateTimeString();
                return Carbon::parse($time)->addMonth(1)->toDateString();
            }
        }
    }

    private function getChannelName($channel_id)
    {
        if ($channel_id == 0) {
            return 'APP';
        } else {
            $source = SettingSource::where('source_id', $channel_id)->first();
            return $source ? $source->source_name : '';
        }
    }


    public static function formatPercentData($data)
    {
        $percent1 = $data['pv'] && $data['uv'] ? bcdiv(bcsub($data['pv'], $data['uv']), $data['pv'], 4) : 0;
        ($data['uv'] == 0 && $data['pv'] > 0) && $percent1 = 1;
        //落地页uv流失率
        $data['uv_loss_percent'] = bcmul($percent1, 100, 2) . '%';
        //注册流失率
        $percent2 = $data['register_num'] && $data['uv'] ? bcdiv(bcsub($data['uv'], $data['register_num']), $data['uv'], 4) : 0;
        ($data['register_num'] == 0 && $data['uv'] > 0) && $percent2 = 1;
        $data['register_num_loss_percent'] = bcmul($percent2, 100, 2) . '%';
        //登录流失率
        $percent3 = $data['register_num'] && $data['login_num'] ? bcdiv(bcsub($data['register_num'], $data['login_num']), $data['register_num'], 4) : 0;
        ($data['login_num'] == 0 && $data['register_num'] > 0) && $percent3 = 1;
        $data['login_loss_percent'] = bcmul($percent3, 100, 2) . '%';
        //申请借钱流失率
        $percent4 = $data['want_loan'] && $data['login_num'] ? bcdiv(bcsub($data['login_num'], $data['want_loan']), $data['login_num'], 4) : 0;
        ($data['want_loan'] == 0 && $data['login_num'] > 0) && $percent4 = 1;
        $data['want_loan_loss_percent'] = bcmul($percent4, 100, 2) . '%';
        //实名认证流失率
        $percent5 = $data['card_submit'] && $data['want_loan'] ? bcdiv(bcsub($data['want_loan'], $data['card_submit']), $data['want_loan'], 4) : 0;
        ($data['card_submit'] == 0 && $data['want_loan'] > 0) && $percent5 = 1;
        $data['card_submit_loss_percent'] = bcmul($percent5, 100, 2) . '%';
        //人脸识别流失率
        $percent6 = $data['face_submit'] && $data['card_submit'] ? bcdiv(bcsub($data['card_submit'], $data['face_submit']), $data['card_submit'], 4) : 0;
        ($data['face_submit'] == 0 && $data['card_submit'] > 0) && $percent6 = 1;
        $data['face_submit_loss_percent'] = bcmul($percent6, 100, 2) . '%';
        //个人信息流失率
        $percent7 = $data['contact_submit'] && $data['face_submit'] ? bcdiv(bcsub($data['face_submit'], $data['contact_submit']), $data['face_submit'], 4) : 0;
        ($data['contact_submit'] == 0 && $data['face_submit'] > 0) && $percent7 = 1;
        $data['contact_submit_loss_percent'] = bcmul($percent7, 100, 2) . '%';
        //添加储蓄卡流失率
        $percent8 = $data['debit_card_submit'] && $data['contact_submit'] ? bcdiv(bcsub($data['contact_submit'], $data['debit_card_submit']), $data['contact_submit'], 4) : 0;
        ($data['debit_card_submit'] == 0 && $data['contact_submit'] > 0) && $percent8 = 1;
        $data['debit_card_submit_loss_page'] = bcmul($percent8, 100, 2) . '%';
        //添加信用卡流失率
        $percent9 = $data['credit_card_submit'] && $data['debit_card_submit'] ? bcdiv(bcsub($data['debit_card_submit'], $data['credit_card_submit']), $data['debit_card_submit'], 4) : 0;
        ($data['credit_card_submit'] == 0 && $data['debit_card_submit'] > 0) && $percent9 = 1;
        $data['credit_card_submit_loss_page'] = bcmul($percent9, 100, 2) . '%';

        //通讯录认证流失率
        $percent11 = $data['phone_auth'] && $data['credit_card_submit'] ? bcdiv(bcsub($data['credit_card_submit'], $data['phone_auth']), $data['credit_card_submit'], 4) : 0;
        ($data['phone_auth'] == 0 && $data['credit_card_submit'] > 0) && $percent11 = 1;
        $data['phone_auth_loss_percent'] = bcmul($percent11, 100, 2) . '%';
        //芝麻信用流失率
        $percent12 = $data['zhima_auth'] && $data['phone_auth'] ? bcdiv(bcsub($data['phone_auth'], $data['zhima_auth']), $data['phone_auth'], 4) : 0;
        ($data['zhima_auth'] == 0 && $data['phone_auth'] > 0) && $percent12 = 1;
        $data['zhima_auth_loss_percent'] = bcmul($percent12, 100, 2) . '%';
        //认证页流失率
        $percent10 = $data['auth_submit'] && $data['zhima_auth'] ? bcdiv(bcsub($data['zhima_auth'], $data['auth_submit']), $data['zhima_auth'], 4) : 0;
        ($data['auth_submit'] == 0 && $data['zhima_auth'] > 0) && $percent10 = 1;
        $data['auth_submit_loss_percent'] = bcmul($percent10, 100, 2) . '%';
        //确认申请流失率
        $percent13 = $data['confirm_submit'] && $data['auth_submit'] ? bcdiv(bcsub($data['auth_submit'], $data['confirm_submit']), $data['auth_submit'], 4) : 0;
        ($data['confirm_submit'] == 0 && $data['auth_submit'] > 0) && $percent13 = 1;
        $data['confirm_submit_loss_percent'] = bcmul($percent13, 100, 2) . '%';
        return $data;
    }

    /**
     * Description: 根据 天/小时 渠道/总渠道 指定时间 获取用户渠道数据
     * Author: WangSx
     * @param string $channel_lock 渠道开关 : 1 开  2 关
     * @param string $flag 时间类型 : day 天 hour 小时
     * @param string $start_time 开始时间
     * @param string $end_time 结束时间
     * @param string $channel 渠道ID  多个用逗号分隔
     * @param string $type 暂时没有用到
     * @return array
     */
    public function queryData($channel_lock, $flag, $start_time, $end_time, $channel, $type)
    {
        if ($channel_lock == 1) {
            $key = $flag . ':user_follow:' . $channel_lock . (!empty($channel) ? ':' . $channel : '');
        } else {
            $key = $flag . ':user_follow:' . $channel_lock;
        }
        $key .= ':' . $start_time . ':' . $end_time;

        $min = 50; //默认存储50分钟
        if ($flag == 'hour') {
            // 按小时
            $data = \Cache::remember($key, $min, function () use ($start_time, $end_time, $channel) {
                return UserFollowCacheHour::getData($start_time, $end_time, $channel);
            });
        } else {
            //按天
            $data = \Cache::remember($key, $min, function () use ($start_time, $end_time, $channel) {
                return UserFollowCacheDay::getData($start_time, $end_time, $channel);
            });
        }

        if (empty($data)) {
            \Cache::forget($key);
            $data = [];
        }

        $result = $this->processData($data, $channel_lock);

        if ($channel_lock == 2) {
            // 总渠道需要将时间日期重新赋值,所有流失率重新计算
            $result = array_reduce($result, function ($carry, $item) {
                $carry[] = static::formatPercentData($item);
                return $carry;
            });
        }

        return $result;
    }


    /**
     * Description: 处理原始数据
     * Author: WangSx
     * @param array $data 原数据
     * @param string $channel_lock 渠道开关 : 1 开  2 关
     * @return array
     */
    public function processData($data, $channel_lock)
    {
        $res = array_reduce($data, function ($carry, $item) use ($channel_lock) {
            if ($channel_lock == 1) {
                // 如果区分渠道, 只需要直接组装丢出即可
                $tmpCarry = static::disposeData($carry, $item);
            } else {
                // 不分渠道 需要相加
                $tmpCarry = static::disposeData($carry, $item, true);
            }

            return $tmpCarry;
        });

        empty($res) && $res = [];

        return $res;
    }

    /**
     * Description: 原始数据处理
     * Author: WangSx
     * @param array|null $carry 地址引用数据
     * @param array $item 需要分析数据
     * @param bool $status 渠道开关 true 不区分渠道
     * @return mixed
     */
    public static function disposeData(&$carry, $item, $status = false)
    {
        $type_total_arr = json_decode($item['type_total'], true);

        if (isset($item['hour'])) {
            $uniqueKey = $item['date'] . ' ' . $item['hour'] . ':00:00';
        } else {
            $uniqueKey = $item['date'];
        }

        if ($status) {
            //不区分渠道
            if (!isset($carry[$uniqueKey])) {
                $carry[$uniqueKey]['start_statistics_time'] = $item['date'];
                $carry[$uniqueKey]['end_statistics_time'] = $uniqueKey;
                $carry[$uniqueKey]['login_num'] = $type_total_arr['login_num'];
                $carry[$uniqueKey]['card_submit'] = $type_total_arr['card_submit'];
                $carry[$uniqueKey]['face_submit'] = $type_total_arr['face_submit'];
                $carry[$uniqueKey]['contact_submit'] = $type_total_arr['contact_submit'];
                $carry[$uniqueKey]['debit_card_submit'] = $type_total_arr['debit_card_submit'];
                $carry[$uniqueKey]['credit_card_submit'] = $type_total_arr['credit_card_submit'];
                $carry[$uniqueKey]['phone_auth'] = $type_total_arr['phone_auth'];
                $carry[$uniqueKey]['zhima_auth'] = $type_total_arr['zhima_auth'];
                $carry[$uniqueKey]['auth_submit'] = $type_total_arr['auth_submit'];
                $carry[$uniqueKey]['confirm_submit'] = $type_total_arr['confirm_submit'];
                $carry[$uniqueKey]['register_num'] = $type_total_arr['register_num'];
                $carry[$uniqueKey]['want_loan'] = $type_total_arr['want_loan'];
                $carry[$uniqueKey]['pv'] = $type_total_arr['pv'];
                $carry[$uniqueKey]['uv'] = $type_total_arr['uv'];
            } else {
                $carry[$uniqueKey]['login_num'] += $type_total_arr['login_num'];
                $carry[$uniqueKey]['card_submit'] += $type_total_arr['card_submit'];
                $carry[$uniqueKey]['face_submit'] += $type_total_arr['face_submit'];
                $carry[$uniqueKey]['contact_submit'] += $type_total_arr['contact_submit'];
                $carry[$uniqueKey]['debit_card_submit'] += $type_total_arr['debit_card_submit'];
                $carry[$uniqueKey]['credit_card_submit'] += $type_total_arr['credit_card_submit'];
                $carry[$uniqueKey]['phone_auth'] += $type_total_arr['phone_auth'];
                $carry[$uniqueKey]['zhima_auth'] += $type_total_arr['zhima_auth'];
                $carry[$uniqueKey]['auth_submit'] += $type_total_arr['auth_submit'];
                $carry[$uniqueKey]['confirm_submit'] += $type_total_arr['confirm_submit'];
                $carry[$uniqueKey]['register_num'] += $type_total_arr['register_num'];
                $carry[$uniqueKey]['want_loan'] += $type_total_arr['want_loan'];
                $carry[$uniqueKey]['pv'] += $type_total_arr['pv'];
                $carry[$uniqueKey]['uv'] += $type_total_arr['uv'];
            }

        } else {
            //区分渠道,直接数据组装丢出
            $carry[] = array(
                'start_statistics_time' => $item['date'],
                'end_statistics_time' => $uniqueKey,
                'channel' => $item['channel'],
                'channel_name' => !empty($item['channel_name']) ? $item['channel_name'] : ($item['channel'] === 0 ? 'APP' : ''),
                'login_num' => $type_total_arr['login_num'],
                'card_submit' => $type_total_arr['card_submit'],
                'face_submit' => $type_total_arr['face_submit'],
                'contact_submit' => $type_total_arr['contact_submit'],
                'debit_card_submit' => $type_total_arr['debit_card_submit'],
                'credit_card_submit' => $type_total_arr['credit_card_submit'],
                'phone_auth' => $type_total_arr['phone_auth'],
                'zhima_auth' => $type_total_arr['zhima_auth'],
                'auth_submit' => $type_total_arr['auth_submit'],
                'confirm_submit' => $type_total_arr['confirm_submit'],
                'register_num' => $type_total_arr['register_num'],
                'want_loan' => $type_total_arr['want_loan'],
                'pv' => $type_total_arr['pv'],
                'uv' => $type_total_arr['uv'],
                'uv_loss_percent' => $type_total_arr['uv_loss_percent'],
                'register_num_loss_percent' => $type_total_arr['register_num_loss_percent'],
                'login_loss_percent' => $type_total_arr['login_loss_percent'],
                'want_loan_loss_percent' => $type_total_arr['want_loan_loss_percent'],
                'card_submit_loss_percent' => $type_total_arr['card_submit_loss_percent'],
                'face_submit_loss_percent' => $type_total_arr['face_submit_loss_percent'],
                'contact_submit_loss_percent' => $type_total_arr['contact_submit_loss_percent'],
                'debit_card_submit_loss_page' => $type_total_arr['debit_card_submit_loss_page'],
                'credit_card_submit_loss_page' => $type_total_arr['credit_card_submit_loss_page'],
                'phone_auth_loss_percent' => $type_total_arr['phone_auth_loss_percent'],
                'zhima_auth_loss_percent' => $type_total_arr['zhima_auth_loss_percent'],
                'auth_submit_loss_percent' => $type_total_arr['auth_submit_loss_percent'],
                'confirm_submit_loss_percent' => $type_total_arr['confirm_submit_loss_percent'],
            );
        }

        return $carry;
    }

}
